﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_menurightInfo
    {
        private int _menuid;
        private int _groupid;
        private string _note;
        private bool _enable_status;

        
        public cs_hmr_menurightInfo()
        {
            this._menuid = 0;
            this._groupid = 0;
            this._note = " ";
            this._enable_status = true;

        }
        public int menuid
        {
            get
            {
                return this._menuid;
            }
            set
            {
                this._menuid = value;
            }
        }
        public int groupid
        {
            get
            {
                return this._groupid;
            }
            set
            {
                this._groupid = value;
            }
        }
        public string note
        {
            get
            {
                return this._note;
            }
            set
            {
                this._note = value;
            }
        }
        public bool enable_status
        {
            get
            {
                return this._enable_status;
            }
            set
            {
                this._enable_status = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[5];
            paraName[0] = "@menuid";
            paraName[1] = "@groupid";
            paraName[2] = "@note";
            paraName[3] = "@enable_status";
            paraName[4] = "@option";
            object[] paraValue = new object[5];
            paraValue[0] = this._menuid;
            paraValue[1] = this._groupid;
            paraValue[2] = this._note;
            paraValue[3] = this._enable_status;
            paraValue[4] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 5, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[4];
            fields[0] = "menuid";
            fields[1] = "groupid";
            fields[2] = "note";
            fields[3] = "enable_status";
            list.KetDulieu(myList, "HMR_MenuRight", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_MenuRight", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("groupid", "menuid");
            cb.KetDuLieu(cbo, "HMR_MenuRight", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[4];
            header[0] = "menuid";
            header[1] = "groupid";
            header[2] = "note";
            header[3] = "enable_status";

            string[] mappingname = new string[4];
            mappingname[0] = "menuid";
            mappingname[1] = "groupid";
            mappingname[2] = "note";
            mappingname[3] = "enable_status";

            int[] colwidth = new int[4];
            colwidth[0] = 12;
            colwidth[1] = 12;
            colwidth[2] = 1200;
            colwidth[3] = 3;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_MenuRight", datagrid, csdl.OpenTable("HMR_MenuRight", condition), header, mappingname, colwidth, 4);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_MenuRight", "menuid = " + this._menuid + " and groupid = " + this._groupid);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._menuid = Convert.ToInt32(ds.Tables[0].Rows[0]["menuid"].ToString().Trim());
                this._groupid = Convert.ToInt32(ds.Tables[0].Rows[0]["groupid"].ToString().Trim());
                this._note = ds.Tables[0].Rows[0]["note"].ToString().Trim();
                this._enable_status = Convert.ToBoolean(ds.Tables[0].Rows[0]["enable_status"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.menu_id, a.menu_name, b.menu_name as captren, a.menu_task, c.enable_status"
                        + " from hmr_menu a"
                        + " left join hmr_menuright c on (c.menuid = a.menu_id)"
                        + " left join hmr_menu b on (a.id_menu_cha = b.menu_id)"
                        + " where  c.groupid = " + this._groupid
                        + " order by a.menu_name asc";
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
